// var i;
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
// var AL_GAME_HUA_EventConfig = require("./AL_GAME_HUA_EventConfig");
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_MissionConfig = require("./AL_GAME_HUA_MissionConfig");
// var AL_GAME_HUA_CurrencyData = require("./AL_GAME_HUA_CurrencyData");
// var AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");
// var P = cc._decorator;
// var g = P.ccclass;
// var y = P.property;
// var m =
//     (P.menu,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.icon = null;
//             t.label_time = null;
//             t.node_button_price = null;
//             t.label_button_price = null;
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.start = function () {
//             this.vibrate();
//             AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
//                 target: this.node,
//                 showAll: !0
//             });
//         };
//         t.prototype.zhixing_chushihua_chuli = function (e) {
//             this.options = e;
//             this.label_time.string = "+" + this.options.time + "s";
//             this.node_button_price.active = AL_GAME_HUA_GameConst.GameConst.getInstance().coin_buy_prop_enabled;
//             this.label_button_price.string = AL_GAME_HUA_GameConst.GameConst.getInstance().revive_price.toString();
//         };
//         t.prototype.chuli_fanhui_anniu_chumo_shijian = function () {
//             if (this.options.onGiveUp) {
//                 this.options.onGiveUp();
//             }
//             this.close();
//         };
//         t.prototype.vibrate = function () {
//             cc.tween(this.icon)
//                 .delay(1)
//                 .by(0.05, {
//                     angle: 15
//                 })
//                 .by(0.1, {
//                     angle: -30
//                 })
//                 .by(0.1, {
//                     angle: 30
//                 })
//                 .by(0.1, {
//                     angle: -30
//                 })
//                 .by(0.1, {
//                     angle: 30
//                 })
//                 .by(0.05, {
//                     angle: -15
//                 })
//                 .union()
//                 .repeatForever()
//                 .start();
//         };
//         t.prototype.handle_button_callback = function (e, t) {
//             var n = this;
//             switch (t) {
//                 case "video":
//                     AL_GAME_HUA_Common.Common.showVideo({
//                         success: function (e) {
//                             if (n.options.onVideo) {
//                                 n.options.onVideo();
//                             }
//                             AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportTransform({
//                                 source: AL_GAME_HUA_EventConfig.AssetsSource.game,
//                                 action:
//                                     2 == e.type
//                                         ? AL_GAME_HUA_EventConfig.AssetsAction.video_get
//                                         : AL_GAME_HUA_EventConfig.AssetsAction.share_get,
//                                 goodsList: [
//                                     {
//                                         goods: AL_GAME_HUA_GoodsConfig.GoodsId.revive,
//                                         num: 1
//                                     }
//                                 ]
//                             });
//                             AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().tianjia_renwu_shuliang_by_leixing(
//                                 AL_GAME_HUA_MissionConfig.MissionType.REVIVE
//                             );
//                             n.close();
//                         },
//                         completed: function () {
//                             n.yincang_block_top();
//                         }
//                     });
//                     break;
//                 case "coin":
//                     AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().shiyong_huobi({
//                         type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
//                         num: AL_GAME_HUA_GameConst.GameConst.getInstance().revive_price
//                     }).result
//                         ? (this.options.onVideo && this.options.onVideo(),
//                           AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportTransform({
//                               source: AL_GAME_HUA_EventConfig.AssetsSource.game,
//                               action: AL_GAME_HUA_EventConfig.AssetsAction.coin_get,
//                               goodsList: [
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.revive,
//                                       num: 1
//                                   },
//                                   {
//                                       goods: AL_GAME_HUA_GoodsConfig.GoodsId.gold,
//                                       num: -AL_GAME_HUA_GameConst.GameConst.getInstance().revive_price
//                                   }
//                               ]
//                           }),
//                           this.close())
//                         : AL_GAME_HUA_AddPrefab.AddPrefab.create_add_gold();
//                     break;
//                 case "close":
//                     if (this.options.onGiveUp) {
//                         this.options.onGiveUp();
//                     }
//                     this.close();
//             }
//         };
//         __decorate([y(cc.Node)], t.prototype, "icon", void 0);
//         __decorate([y(cc.Label)], t.prototype, "label_time", void 0);
//         __decorate([y(cc.Node)], t.prototype, "node_button_price", void 0);
//         __decorate([y(cc.Label)], t.prototype, "label_button_price", void 0);
//         return __decorate([g], t);
//     })(AL_GAME_HUA_PopupSelf.default));
// exports.default = m;


// 引入所需模块
const AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
const AL_GAME_HUA_PopupSelf = require("./AL_GAME_HUA_PopupSelf");
const AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
const AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
const AL_GAME_HUA_EventConfig = require("./AL_GAME_HUA_EventConfig");
const AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
const AL_GAME_HUA_MissionConfig = require("./AL_GAME_HUA_MissionConfig");
const AL_GAME_HUA_CurrencyData = require("./AL_GAME_HUA_CurrencyData");
const AL_GAME_HUA_GoodsConfig = require("./AL_GAME_HUA_GoodsConfig");

const { ccclass, property, menu } = cc._decorator;

/**
 * @class PopupHandler
 * 弹出框处理类
 */
@ccclass
class PopupHandler extends AL_GAME_HUA_PopupSelf.default {
    /** 图标节点 */
    @property(cc.Node)
    icon = null;

    /** 时间标签 */
    @property(cc.Label)
    label_time = null;

    /** 价格按钮节点 */
    @property(cc.Node)
    node_button_price = null;

    /** 价格标签 */
    @property(cc.Label)
    label_button_price = null;

    /**
     * 初始化函数
     */
    start() {
        this.vibrate();
        AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
            target: this.node,
            showAll: true
        });
    }

    /**
     * 初始化选项
     * @param {Object} options - 配置选项
     */
    zhixing_chushihua_chuli(options) {
        this.options = options;
        this.label_time.string = `+${this.options.time}s`;
        this.node_button_price.active = AL_GAME_HUA_GameConst.GameConst.getInstance().coin_buy_prop_enabled;
        this.label_button_price.string = AL_GAME_HUA_GameConst.GameConst.getInstance().revive_price.toString();
    }

    /**
     * 返回按钮触碰处理
     */
    chuli_fanhui_anniu_chumo_shijian() {
        if (this.options.onGiveUp) {
            this.options.onGiveUp();
        }
        this.close();
    }

    /**
     * 图标震动效果
     */
    vibrate() {
        cc.tween(this.icon)
            .delay(1)
            .by(0.05, { angle: 15 })
            .by(0.1, { angle: -30 })
            .by(0.1, { angle: 30 })
            .by(0.1, { angle: -30 })
            .by(0.1, { angle: 30 })
            .by(0.05, { angle: -15 })
            .union()
            .repeatForever()
            .start();
    }

    /**
     * 按钮回调处理
     * @param {Event} event - 事件对象
     * @param {string} type - 按钮类型
     */
    handle_button_callback(event, type) {
        switch (type) {
            case "video":
                this.handle_Video_Callback();
                break;
            case "coin":
                this.handle_Coin_Callback();
                break;
            case "close":
                this.handle_Close_Callback();
                break;
        }
    }

    /**
     * 处理视频按钮回调
     */
    handle_Video_Callback() {
        AL_GAME_HUA_Common.Common.showVideo({
            success: (result) => {
                if (this.options.onVideo) {
                    this.options.onVideo();
                }
                this.report_Assets_Transform(result);
                AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().tianjia_renwu_shuliang_by_leixing(
                    AL_GAME_HUA_MissionConfig.MissionType.REVIVE
                );
                this.close();
            },
            completed: () => {
                this.yincang_block_top();
            }
        });
    }

    /**
     * 处理货币按钮回调
     */
    handle_Coin_Callback() {
        if (
            AL_GAME_HUA_CurrencyData.CurrencyData.getInstance().shiyong_huobi({
                type: AL_GAME_HUA_CurrencyData.CurrencyType.COIN,
                num: AL_GAME_HUA_GameConst.GameConst.getInstance().revive_price
            }).result
        ) {
            if (this.options.onVideo) {
                this.options.onVideo();
            }
            this.report_Assets_Transform({ type: 2 });
            this.close();
        } else {
            AL_GAME_HUA_AddPrefab.AddPrefab.create_add_gold();
        }
    }

    /**
     * 处理关闭按钮回调
     */
    handle_Close_Callback() {
        if (this.options.onGiveUp) {
            this.options.onGiveUp();
        }
        this.close();
    }

    /**
     * 资产转换报告
     * @param {Object} result - 视频播放结果
     */
    report_Assets_Transform(result) {
        AL_GAME_HUA_EventConfig.EventConfig.getInstance().assetsReportTransform({
            source: AL_GAME_HUA_EventConfig.AssetsSource.game,
            action:
                result.type === 2
                    ? AL_GAME_HUA_EventConfig.AssetsAction.video_get
                    : AL_GAME_HUA_EventConfig.AssetsAction.share_get,
            goodsList: [
                {
                    goods: AL_GAME_HUA_GoodsConfig.GoodsId.revive,
                    num: 1
                }
            ]
        });
    }
}

exports.default = PopupHandler;
